/**
 * Created by lvlq on 16/3/12.
 */
var Sequelize = require("sequelize");
var sequelize = Util("sequelize");

module.exports = sequelize.define("toplist", {
    openid: {
        type: Sequelize.STRING,
        field: "openid",
        allowNull: false,
        defaultValue: "",
        comment: "用户id"
    },
    nickname: {
        type: Sequelize.TEXT,
        field: "nickname",
        allowNull: false,
        defaultValue: "",
        comment: "微信昵称",
        set: function (val) {
            var base64 = new Buffer(val).toString("base64");
            this.setDataValue('nickname', base64);
        },
        get: function () {
            var val = this.getDataValue('nickname');
            var s = new Buffer(val, 'base64').toString();
            return s;
        }
    },
    headimgurl: {
        type: Sequelize.STRING,
        field: "headimgurl",
        allowNull: false,
        defaultValue: "",
        comment: "微信头像"
    },
    pid: {
        type: Sequelize.INTEGER,
        field: "pid",
        allowNull: false,
        defaultValue: 0,
        comment: "奖品id"
    },
    pname: {
        type: Sequelize.STRING,
        field: "pname",
        allowNull: false,
        defaultValue: "",
        comment: "奖品name"
    },
    name: {
        type: Sequelize.STRING,
        field: "name",
        allowNull: false,
        defaultValue: "",
        comment: "姓名"
    },
    phone: {
        type: Sequelize.STRING,
        field: "phone",
        allowNull: false,
        defaultValue: 0,
        comment: "手机号"
    }
}, {
    indexes: [
        {
            fields: ["openid"]
        }
    ]
});